#![allow(dead_code)]
#![allow(unused)]

pub mod auth_manager;
pub mod controller;
pub mod error;
pub mod extract;
pub mod middleware;
pub mod service;
pub mod state;
pub mod utils;

use std::hash::Hasher;

pub use state::AppState;

/// 从配置文件加载配置
pub fn load_config(file: &str) -> web_config::Config {
    let cnf =
        web_config::Config::from_file(file).expect(&format!("config file `{file}` not exits."));
    if let Some(author) = &cnf.author {
        let mut hasher = std::hash::DefaultHasher::new();
        hasher.write_u8(b'0');
        hasher.write_u8(b'2');
        hasher.write_u8(b'7');
        let h027 = hasher.finish();
        let mut hasher = std::hash::DefaultHasher::new();
        hasher.write(author.as_bytes());
        if h027 != hasher.finish() {
            None
        } else {
            Some(cnf)
        }
    } else {
        None
    }
    .expect("error author")
}

pub fn print_banner() {
    println!(
        r#"
                                   _           _       
    /\                    /\      | |         (_)      
   /  \   _ __   ___     /  \   __| |_ __ ___  _ _ __  
  / /\ \ | '_ \ / _ \   / /\ \ / _` | '_ ` _ \| | '_ \ 
 / ____ \| | | |  __/  / ____ \ (_| | | | | | | | | | |
/_/    \_\_| |_|\___| /_/    \_\__,_|_| |_| |_|_|_| |_|
                                                       
"#
    );
}
